#include <iostream>
#include <safe_vector.h>
#include <safe_algorithm.h>

//define what should be done for this program in case of a bounds error
void bounds_error()
{
   std::cout<<"bounds error occured. provoking coredump to safely fail."<<std::endl;
   std::cerr<<"bounds error occured. provoking coredump to safely fail."<<std::endl;
   char* provoke_coredump=NULL;
   provoke_coredump[0]='0';
}

//define what should be done for this program in case of an iterator error
void iterator_error()
{
   std::cout<<"iterator error occured. provoking coredump to safely fail."<<std::endl;
   std::cerr<<"iterator error occured. provoking coredump to safely fail."<<std::endl;
   char* provoke_coredump=NULL;
   provoke_coredump[0]='0';
}


int main(int argc,char** argv)
{

    safe_stl::vector<int> v;
    safe_stl::vector<int> v2;
    v.resize(10);
    v[0]=0;
    v[1]=100;
    v[2]=200;
    v[3]=300;
    v[4]=400;
    v[5]=500;
    v[6]=600;
    v[7]=700;
    v[8]=800;
    v[9]=900;
    //fail 1 v[10]=1111;
    for(safe_stl::vector<int>::iterator it=v.begin();!(it == v.end());++it)
    {
       std::cout<< *it << std::endl;
    }
    safe_stl::vector<int>::iterator it2= v.begin();
    safe_stl::vector<int>::iterator it3= v2.end();
    //while(! (it2 == it3) )
    //  std::cout<<"I must not runt"<<std::endl;

    v.resize(30);
    int i=10;
    v[i++]=19999;
    v[i++]=11;
    v[i++]=1;
    v[i++]=1100;
    v[i++]=131;
    v[i++]=41;
    v[i++]=11;
    v[i++]=61;
    v[i++]=19;
    v[i++]=45;
    v[i++]=1;
    v[i++]=1;
    v[i++]=1;
    v[i++]=61;
    v[i++]=91;
    v[i++]=31;
    v[i++]=991;
    v[i++]=61;
    v[i++]=96;
    v[i++]=1111;
    merge_sort(v.begin(),v.end());
    int old = v[0];
    for(safe_stl::vector<int>::iterator it=v.begin();it != v.end();it++)
    {
        if(*it < old)
          std::cout<<"sort did not work properly"<<std::endl;
        old = *it;
        std::cout << *it << " ";
    }
    std::cout<<std::endl;
    
}
